import JCRequest from './request'
import { sessionCache } from '@/utils/cache'

const request = new JCRequest({
  // baseURL: 'http://localhost:3000/api',
  timeout: 5000,
  interceptors: {
    // 请求拦截器
    requestSuccessFn: (config) => {
      // 每一个请求都自动携带token
      const token = sessionCache.getCache(LOGIN_TOKEN)
      if (config.headers && token) {
        // 类型缩小
        config.headers.Authorization = 'Bearer ' + token
      }
      return config
    }
  }
})

export default request
